﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WorkRecord.CommonClass;

namespace WorkRecord
{
    public partial class WorkMajorEnter : System.Web.UI.Page
    {
        public DataAccess da = new DataAccess();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        public void InitPage()
        {
            var dt = da.GetMajorWorj(WebContext.Current.CurrentUser.Rows[0]["username"].ToString());
            if (dt != null && dt.Rows.Count > 0)
            {
                txtContent.Text = dt.Rows[0]["CurrMonthMajorWorkork"].ToString();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var paras = new SqlParameter[3];
            paras[0] = new SqlParameter("@UserAccount", WebContext.Current.CurrentUser.Rows[0]["username"]);
            paras[1] = new SqlParameter("@CurrMonthMajorWorkork", txtContent.Text);
            paras[2] = new SqlParameter("@SubmitTime", DateTime.Now);
            string sql = @"insert into JourneyMajorWork(UserAccount,CurrMonthMajorWorkork,SubmitTime) values(@UserAccount,@CurrMonthMajorWorkork,@SubmitTime)";
            da.datacmd(sql, paras);

            Response.Redirect("/WorkView.aspx");
        }
    }
}